<template>
  <div class="auto">
    <partial-view v-ref:pv>
      <hand-plan-list  :row='model'></hand-plan-list>
    </partial-view>
    <machine-meter-center :row='model'></machine-meter-center>
  </div>
</template>
<script>
import co from 'co'

let load = function * (self, id) {
  let res = yield self.$refs.pv.load('rs/sql/getOverdue', {data: {f_user_id: id}})
  self.$info(res.data)
  if (res.data) {
    self.model.rows = [...self.model.rows, ...res.data]
  }
  self.$info(self.model.rows)
  return res
}
/**
*售气收费
*机表收费组合组件，包括抄表列表以及机表收费主组件
*/
export default {
  title: '机表收费',
  data () {
    return {
      model: {
        logicmodel: {
          f_payment: '',
          f_pregas: 0,
          f_preamount: 0,
          f_totalcost: 0,
          f_curbalance: 0,
          f_collection: '',
          f_balance: 0,
          f_overdue: 0,
          f_lowest: 0,
          f_print: ''
        },
        rows: []
      }
    }
  },
  props: ['row'],
  ready () {
    this.model = Object.assign({}, this.model, this.row)
    this.getList(this.model.f_user_id).then((res) => {
      this.initData(this.model)
      this.getRows(res.data)
    })
  },
  methods: {
    getList (id) {
      let getData = load(this, id)
      return co(getData)
    },
    initData (row) {
      console.log('12222222222222222222222222')
      this.model.logicmodel.f_price_id = row.f_price_id
      this.model.logicmodel.f_user_id = row.f_user_id
      this.model.logicmodel.f_balance = row.f_balance
    },
    getRows (val) {
      if (val.length === 0) {
        return
      }
      let logic = this.model.logicmodel
      // logic.f_lowest = logic.f_lowest - (logic.f_balance - 0) > 0 ? logic.f_lowest - (logic.f_balance - 0) : 0
      logic.f_lowest = logic.f_lowest - (logic.f_balance - 0)
      if (val[0].overdue <= 0) {
        logic.f_lowest = logic.f_lowest + val[0].f_oughtfee
        logic.f_overdue = 0
        val.forEach((item) => {
          logic.f_pregas = logic.f_pregas + item.f_oughtamount
          logic.f_preamount = logic.f_preamount + item.f_oughtfee
        })
      } else {
        val.forEach((item) => {
          logic.f_pregas = logic.f_pregas + item.f_oughtamount
          logic.f_preamount = logic.f_preamount + item.f_oughtfee
          logic.f_overdue = logic.f_overdue + item.overdue
          if (item.overdue > 0) {
            logic.f_lowest = logic.f_lowest + item.f_oughtfee + item.overdue
          }
        })
      }
      logic.f_overdue = logic.f_overdue.toFixed(2)
	   logic.f_totalcost = (logic.f_preamount - 0) + (logic.f_overdue - 0) - (logic.f_balance - 0) > 0 ? (logic.f_preamount - 0) + (logic.f_overdue - 0) - (logic.f_balance - 0) : 0

    }
  }
}
</script>
<style lang="less">
#tooltip div{
  height: auto;
}
</style>
